package mk.timska_rabota_android;



import com.google.android.gms.maps.CameraUpdateFactory;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.LocationSource;
import com.google.android.gms.maps.MapView;
import com.google.android.gms.maps.SupportMapFragment;
import com.google.android.gms.maps.model.LatLng;

import android.location.Criteria;
import android.location.Location;
import android.location.LocationListener;
import android.location.LocationManager;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.widget.Toast;

import java.io.IOException;
import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.ArrayList;


import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;

import android.view.Menu;
import android.view.MenuInflater;



import com.google.android.gms.maps.model.BitmapDescriptorFactory;

import com.google.android.gms.maps.model.LatLngBounds;
import com.google.android.gms.maps.model.MarkerOptions;
import com.google.android.gms.maps.model.MarkerOptionsCreator;

public class Map extends FragmentActivity {

	private GoogleMap mMap;
	

	ArrayList<LatLngBounds> bounds = new ArrayList<LatLngBounds>();

	// south-west and north-east corner of the bound
	private LatLngBounds SKOPJE = new LatLngBounds(new LatLng(41.961277,
			21.34658), new LatLng(42.035014, 21.507427));

	

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_proba);

	

		setUpMapIfNeeded();
	}

	public boolean onCreateOptionsMenu(Menu menu) {
		MenuInflater inflater = getMenuInflater();
		inflater.inflate(R.menu.proba, menu);
		return true;
	}

	

	@Override
	protected void onResume() {
		super.onResume();
		setUpMapIfNeeded();
	}

	private void setUpMapIfNeeded() {
		// Do a null check to confirm that we have not already instantiated the
		// map.
		if (mMap == null) {
			// Try to obtain the map from the SupportMapFragment.
			mMap = ((SupportMapFragment) getSupportFragmentManager()
					.findFragmentById(R.id.map)).getMap();
			// Check if we were successful in obtaining the map.
			if (mMap != null) {
				setUpMap();
			}
		}
	}

	private void setUpMap() {
		double lat, lon;
		Intent intent = getIntent();
		lon = intent.getDoubleExtra("Longitude", 21.452326);
		lat = intent.getDoubleExtra("Latitude", 41.991554);
		LatLng cosmicDevPos = new LatLng(lat , lon);
		
		
		mMap.setMyLocationEnabled(true);
		
		LocationManager locationManager = (LocationManager) getSystemService(LOCATION_SERVICE);
		
		Criteria criteria = new Criteria();
		String provider = locationManager.getBestProvider(criteria, true);
		Location myLocation = locationManager.getLastKnownLocation(provider);
		mMap.setMapType(GoogleMap.MAP_TYPE_HYBRID);
		
		
		mMap.addMarker(new MarkerOptions().position(cosmicDevPos).title("Hello World"));		
		// center the map at Skopje, with zoom level of 20
		mMap.moveCamera(CameraUpdateFactory.newLatLngZoom(cosmicDevPos,13));
	}





}


